package com.bpms.atmp.client.common;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Vector;


public class GVO implements java.io.Serializable {
	private int index = 0;
	private String voType;
	private String serviceName;

	private Map<String, String> mapStr;
	private Map<String, GVO> mapGVO;
	private Map<String, GVOList> mapGVOList;
	private Map<String, GVOL> mapGVOL;

	private Vector<String> orderKeys = new Vector<String>();

	public String getServiceName() {
		return serviceName;
	}

	public void setServiceName(String serviceName) {
		this.serviceName = serviceName;
	}

	public void setAttr(String k, String v) {
		if (mapStr == null) {
			mapStr = new HashMap<String, String>();
		}
		k = k.toUpperCase();
		mapStr.put(k, v);
		index++;
	}

	public void setAttrInOrder(String k, String v) {
		if (mapStr == null) {
			mapStr = new HashMap<String, String>();
		}
		k = k.toUpperCase();
		orderKeys.add(k);
		mapStr.put(k, v);
		index++;
	}

	public void clear() {
		if (mapStr != null)
			mapStr.clear();
		if (mapGVO != null)
			mapGVO.clear();
		if (mapGVOList != null)
			mapGVOList.clear();
		if (mapGVOL != null)
			mapGVOL.clear();
		orderKeys.clear();
	}

	public Vector<String> getOrderKeys() {
		return orderKeys;
	}

	
	public void setGVO(String k, GVO gvo) {
		if (mapGVO == null) {
			mapGVO = new HashMap<String, GVO>();
		}
		k = k.toUpperCase();
		mapGVO.put(k, gvo);
		index++;
	}

	public void setGVOList(String k, GVOList gvolist) {
		if (mapGVOList == null) {
			mapGVOList = new HashMap<String, GVOList>();
		}
		k = k.toUpperCase();
		mapGVOList.put(k, gvolist);
		index++;
	}

	public void setGVOL(String k, GVOL gvol) {
		if (mapGVOL == null) {
			mapGVOL = new HashMap<String, GVOL>();
		}
		k = k.toUpperCase();
		mapGVOL.put(k, gvol);
		index++;
	}

	public String getAttr(String k) {
		if (mapStr == null)
			return null;
		k = k.toUpperCase();
		String val=mapStr.get(k);
		if(val==null)val="";
		return val;
	}

	public GVOL getGVOL(String k) {
		if (mapGVOL == null)
			return null;
		k = k.toUpperCase();
		return mapGVOL.get(k);
	}

	public GVOList getGVOList(String k) {
		if (mapGVOList == null)
			return null;
		k = k.toUpperCase();
		return mapGVOList.get(k);
	}

	public GVO getGVO(String k) {
		if (mapGVO == null)
			return null;
		k = k.toUpperCase();
		return mapGVO.get(k);
	}

	
	public void removeAttr(String k) {
		if (mapStr == null)
			return;
		k = k.toUpperCase();
		mapStr.remove(k);
	}
	
	public void removeGVOL(String k) {
		if (mapGVOL == null)
			return;
		k = k.toUpperCase();
		mapGVOL.remove(k);
	}

	public void removeGVOList(String k) {
		if (mapGVOList == null)
			return;
		k = k.toUpperCase();
		mapGVOList.remove(k);
	}

	public void removeGVO(String k) {
		if (mapGVO == null)
			return;
		k = k.toUpperCase();
		mapGVO.remove(k);
	}
	
	public void merge(GVO gvo) {
		if (gvo == null) {
			return;
		}
		Map<String,String> ms=gvo.getMapStr();
		Set<String> set;
		Iterator<String> it;
		if(ms!=null){
			set=ms.keySet();
			it=set.iterator();
			while(it.hasNext()){
				String key=it.next();
				setAttr(key, ms.get(key));
			}
		}
	}

	public String getVoType() {
		return voType;
	}

	public void setVoType(String voType) {
		this.voType = voType;
	}

	public String toString() {
		String s = "";
		s += "Attrs:" + mapStr + ";\r\n";
		s += "GVOs:" + mapGVO + ";\r\n";
		s += "GVOLists:" + mapGVOList + ";\r\n";
		s += "GVOLs:" + mapGVOL + ";\r\n";
		return s;
	}

	public Map<String, String> getMapStr() {
		return mapStr;
	}

	public Map<String, GVO> getMapGVO() {
		return mapGVO;
	}

	public Map<String, GVOList> getMapGVOList() {
		return mapGVOList;
	}

	public Map<String, GVOL> getMapGVOL() {
		return mapGVOL;
	}

	public int size() {
		return index;
	}
	
}
